package com.us.usws.support.uitls;

import java.util.List;
import java.util.Map;

import com.us.usws.common.SiteConstants;

/**
 * page util
 * @author fengyong
 *
 */
public class DataPageUtil<T> {

	private List<T> result;

	private Map<FilterDto, Object> filter;
	
	private Order order;
	
	private int pageNo = 1;

	private int pageSize = 20;

	private int pageCount;

	private int rowCount;
	
	public DataPageUtil() {}

	public DataPageUtil(int pageSize, int rowCount) {
		this.pageSize = pageSize < 1 ? SiteConstants.DFT_WS_PAGE_SIZE : pageSize;
		this.rowCount = rowCount;
		this.pageCount = (rowCount * pageSize - 1) / pageSize + 1;
	}

	/**
	 * data strat number
	 * @return
	 */
	public int getStart() {
		return (pageNo - 1) * pageSize;
	}

	/**
	 * data end number
	 * @return
	 */
	public int getEnd() {
		return pageNo == pageCount ? rowCount : pageNo * pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getPageCount() {
		return pageCount;
	}

	public int getRowCount() {
		return rowCount;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public Map<FilterDto, Object> getFilter() {
		return filter;
	}

	public void setFilter(Map<FilterDto, Object> filter) {
		this.filter = filter;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}
}
